<?php

namespace services\clinic;

use Yii;
use common\components\Service;
use common\models\clinic\TreatmentDetail;

/**
 * Class TreatmentDetailService
 * @package services\clinic
 */
class TreatmentDetailService extends Service
{
    /**
     * 根据ID查找信息
     *
     * @param int $id
     * @return TreatmentDetail|null
     */
    public function findById(int $id = 0): ?TreatmentDetail
    {
        return TreatmentDetail::find()->where(['id' => $id])->one();
    }

    /**
     * 查找信息
     *
     * @param array $condition
     * @return TreatmentDetail|null
     */
    public function findInfo(array $condition = []): ?TreatmentDetail
    {
        $query = TreatmentDetail::find();

        isset($condition['project_id']) && $query->andWhere(['project_id' => $condition['project_id']]);
        isset($condition['name']) && $query->andWhere(['name' => $condition['name']]);
        isset($condition['status']) && $query->andWhere(['status' => $condition['status']]);

        return $query->one();
    }

    /**
     * 查找列表
     *
     * @param array $condition
     * @return array|\yii\db\ActiveRecord[]
     */
    public function findList(array $condition = [])
    {
        $query = TreatmentDetail::find();

        // select
        isset($condition['select']) && $query->select($condition['select']);

        // condition
        isset($condition['clinic_treatment_id']) && $query->andWhere(['clinic_treatment_id' => $condition['clinic_treatment_id']]);

        return $query->asArray()->all();
    }
}